package webserver

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

func Fail(c *gin.Context, err error) {
	c.JSONP(http.StatusOK, gin.H{
		"code": -1,
		"msg":  err.Error(),
	})
}

func Success(c *gin.Context, msg string, val interface{}) {
	if msg == "" {
		msg = "success"
	}
	result := gin.H{
		"code": 0,
		"msg":  msg,
	}
	if val != nil {
		result["data"] = val
	}
	c.JSONP(http.StatusOK, result)
}
